<template>
<view>
<view class="top_view">
    <view>
        <view class="message_border">收货人：{{name}}
      <text class="message_border_right">{{tel}}</text>
        </view>
        <view @tap="addressSave" class="dizhi_border">
            <view class="dizhi_border_img_border">
                <image class="dizhi_border_img" src="/static/pages/image/dingwei_icn.png"></image>
            </view>
            <view class="dizhi_border_text">收货地址：{{address}}</view>
            <view class="dizhi_border_img_border">
                <image class="dizhi_border_backimg" src="/static/pages/image/jiantou_btn.png"></image>
            </view>
        </view>
        <image class="huatiao" src="/static/pages/image/border_line.png"></image>
    </view>
    <view class="style_view">支付方式
      <view style="float:right;color:#b2b2b2">微信支付</view>
    </view>
</view>
<view class="modle_border">
    <view class="modle">
        <image class="modle_img" mode="aspectFill" :src="order_line.part_img"></image>
        <view class="modle_title">{{order_line.part_name}}</view>
        <view class="modle_title_right">x1</view>
        <view class="modle_title_bottom">¥{{order_line.part_price}}</view>
    </view>
    <view class="heji_modle">
        <view style="float:right">小计：
        <text style="font-weight: bold;font-size:30rpx;">¥{{order_line.part_price}}</text>
        </view>
    </view>
</view>
<view class="bottom_nav">
    <form @submit="pay" reportSubmit="true">
        <button class="bottom_nav_btn" form-type="submit">付款</button>
    </form>
    <text style="margin-left:24px;" v-if="kill_status!=1">实付款：¥{{order_line.part_price}}</text>
</view>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
      order_id: 0,
      order_line: [],
      tel: "",
      name: "",
      address: "",
      kill_status: 0
    };
  },

  components: {},
  props: {},
  onLoad: function (a) {
    var t = this,
        e = a.id;
    t.setData({
      order_id: e
    }), app.globalData.util.request({
      url: "entry/wxapp/Api",
      data: {
        m: "monai_market",
        r: "part.order.pay_set",
        uid: app.globalData.getuid(),
        id: e
      },
      success: function (a) {
        t.setData({
          order_line: a.data.data.order
        }), a.data.data.address ? t.setData({
          tel: a.data.data.address.tel,
          name: a.data.data.address.name,
          address: a.data.data.address.address
        }) : t.setAddressFun();
      }
    });
  },
  methods: {
    setAddressFun: function () {
      var s = this;
      wx.chooseAddress({
        success: function (a) {
          var t = a.telNumber,
              e = a.userName,
              d = a.provinceName + " " + a.cityName + " " + a.countyName + " " + a.detailInfo;
          s.setData({
            tel: t,
            name: e,
            address: d
          }), app.globalData.util.request({
            url: "entry/wxapp/Api",
            data: {
              m: "monai_market",
              r: "part.order.address_save",
              uid: app.globalData.getuid(),
              name: e,
              tel: t,
              address: d
            },
            success: function (a) {}
          });
        },
        fail: function (a) {
          wx.showModal({
            content: "收货地址必选",
            showCancel: !1,
            success: function (a) {
              wx.openSetting({
                success: function () {
                  s.setAddressFun();
                }
              });
            }
          });
        }
      });
    },
    addressSave: function () {
      this.setAddressFun();
    },
    pay: function (a) {
      var e = this,
          t = a.detail.formId;
      if (!e.name || !e.tel || !e.address) return wx.showModal({
        content: "请填写收货地址",
        showCancel: !1,
        success: function (a) {
          this.setAddressFun();
        }
      }), !1;
      app.globalData.util.request({
        url: "entry/wxapp/payPartOrder",
        data: {
          m: "monai_market",
          id: this.order_id,
          uid: app.globalData.getuid(),
          formid: t
        },
        success: function (a) {
          if ("OK" == a.data.message && wx.redirectTo({
            url: "/pagesA/part/order/index?status=3"
          }), a.data.data) {
            var t = a.data.data.fid;
            a.data.data.money;
            wx.requestPayment({
              timeStamp: a.data.data.timeStamp,
              nonceStr: a.data.data.nonceStr,
              package: a.data.data.package,
              signType: "MD5",
              paySign: a.data.data.paySign,
              success: function (a) {
                console.log(a), app.globalData.util.request({
                  url: "entry/wxapp/Api",
                  data: {
                    m: "monai_market",
                    r: "part.order.pay_callback",
                    uid: app.globalData.getuid(),
                    oid: e.order_id,
                    fid: t
                  },
                  success: function (a) {
                    console.log(a);
                  }
                }), wx.redirectTo({
                  url: "/pagesA/part/order/index?status=3"
                });
              },
              fail: function (a) {
                wx.redirectTo({
                  url: "/pagesA/part/order/index?status=2"
                });
              }
            });
          }
        },
        fail: function (a) {
          wx.showModal({
            content: "支付失败",
            showCancel: !1,
            success: function (a) {}
          });
        }
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>